/**
 * Created by kayak-lic on 16/11/9.
 */
import React from 'react';
import util from 'util';
import {Switch, Input, Row, Col, Button, Table, Modal, Form, Collapse, Card, Radio, Tabs} from 'antd';
import {SearchDemo, RightButton, ColsEdit, Simeditor} from 'kpl';
import sys_dict from "sys_dict";

class UserdhjResultSelect extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            tblSource: [],
            isLoading: false,
            vidible: false,
        };
        this.searchParams = {
            "page": 1,
            "rows": sys_dict.defaultPageSize.toString(),
        };
    }

    refresh(paramdic) {

        this.setState({isLoading: true});
        util.httpRequest({
            type: "POST", url: 'log040303.json', plattype: 'market/', params: paramdic, success: function (result) {
                this.setState({
                    tblSource: result.rows,
                    totalCount: result.total,
                    isLoading: false,
                });
            }.bind(this)
        });
    }

    handleCancel() {
        this.setState({visible: false});
    }

    //查看兑换记录
    showDetail(record, index) {
        console.log("asdsadas")
        this.setState({visible: true});
        return;
        this.temprecode = record;
        var paramdic = {};
        paramdic.user_id = record.user_id;
        paramdic.activity_id = record.activity_id;
        util.httpRequest({
            type: "POST", url: 'log040306.json', plattype: 'market/', params: paramdic, success: function (result) {
                this.setState({
                    tblSource2: result.rows,
                    tb1model: false,
                    tb2model: true,
                });
            }.bind(this)
        });
    }

    search(params) {
        console.log("param--", params)
        params.get_start_date = util.date2str(params.get_start_date);
        params.get_end_date = util.date2str(params.get_end_date);
        params.upd_start_date = util.date2str(params.upd_start_date);
        params.upd_end_date = util.date2str(params.upd_end_date);
        params.page = "1";
        params.rows = sys_dict.defaultPageSize.toString();
        this.refresh(params);
    }

    onShowSizeChange(current, pageSize) {
        let params = this.searchParams;
        params.rows = pageSize;
        params.page = current;
        this.refresh(params);
    }

    onChange(page) {
        let params = this.searchParams;
        params.page = page;
        this.refresh(params);
    }

    componentDidMount() {
        this.refresh(this.searchParams);
    }

    config() {
        const pagination = {
            total: this.state.totalCount,
            showSizeChanger: true,
            showQuickJumper: true,
            isLoading: false,
            pageSizeOptions: sys_dict.pageSizeOptions,
            defaultPageSize: sys_dict.defaultPageSize,
            onShowSizeChange: this.onShowSizeChange.bind(this),
            onChange: this.onChange.bind(this),
        };

        return {
            tableConfig: {
                pagination: pagination,
                dataSource: this.state.tblSource,
                columns: [
                    {
                        title: '活动类型',
                        dataIndex: 'activity_type',
                        key: 'activity_type',
                        width: 150,
                        render: function (value) {
                            let str = util.convert("activity_type", value);
                            return str;
                        }
                    },
                    {
                        title: '兑换券编号',
                        dataIndex: 'voucher_id',
                        key: 'voucher_id',
                        width: 150,
                    },
                    {
                        title: '客户名称',
                        dataIndex: 'user_name',
                        key: 'user_name',
                        width: 150,
                    }, {
                        title: '客户手机号',
                        dataIndex: 'mobile',
                        key: 'mobile',
                        width: 150,
                    },
                    {
                        title: '活动名称',
                        dataIndex: 'activity_name',
                        key: 'activity_name',
                        width: 150,
                    },
                    {
                        title: '商品名称',
                        dataIndex: 'goods_name',
                        key: 'goods_name',
                        width: 150,
                    },
                    {
                        title: '商品数量 (个)',
                        dataIndex: 'goods_quantity',
                        key: 'goods_quantity',
                        width: 150,
                    }, {
                        title: '市价 (元)',
                        dataIndex: 'market_price',
                        key: 'market_price',
                        width: 150,
                    },
                    {
                        title: '实价 (元)',
                        dataIndex: 'real_price',
                        key: 'real_price',
                        width: 150,
                    },
                    {
                        title: '获取日期时间',
                        dataIndex: 'get_date_time',
                        key: 'get_date_time',
                        width: 150,
                        render: function (value) {
                            let str = util.dateStrFormat(value, "DT");




// asdasd

                            return str;
                        }
                    },
                    {
                        title: '使用日期时间',
                        dataIndex: 'update_time',
                        key: 'update_time',
                        width: 150,
                        render: (text, record, index) => (
                            record.voucher_status === "2" ?
                                <span >{ util.dateStrFormat(record.update_time, "DT")}</span> : <span >未使用</span>
                        )
                    },
                    {
                        title: '兑换券来源',
                        dataIndex: 'voucher_channel',
                        key: 'voucher_channel',
                        width: 150,
                        render: function (value) {
                            let str = util.convert("voucher_channel", value);
                            return str;
                        }
                    },
                    {
                        title: '兑换券图片',
                        dataIndex: 'voucher_pic_url',
                        key: 'voucher_pic_url',
                        width: 150,
                        render: function (value, data, rowIndex) {
                            if (value == null) {
                                return "";
                            }
                            return <a href={util.getImgUrl + value} target="_blank">兑换券图片</a>;
                        }
                    },
                    {
                        title: '兑换券状态',
                        dataIndex: 'voucher_status',
                        key: 'voucher_status',
                        width: 150,
                        render: function (value) {
                            let str = util.convert("voucher_status", value);
                            return str;
                        }
                    }, {
                        title: '操作',
                        dataIndex: '123',
                        key: '123',
                        width: 150,
                        render: (text, record, index) => (<span>
                        <a onClick={this.showDetail.bind(this, record, index)}>查看兑换记录</a>
                        </span>)
                    }]
            },
        }
    }

    render() {

        let config = this.config();
        const searchConfig = {
            searchTitle: "查询条件",
            searchInit: {
                voucher_name: "",
                status: "",
                min_market_price: "",
                max_market_price: "",
                min_real_price: "",
                max_real_price: ""
            },
            searchField: [
                [
                    {propsname: "兑换券状态", propsKey: "voucher_status", propsType: "select", key: "118"},
                    {propsname: "兑换券获得时间", propsKey: "get_start_date", propsType: "datepicker", key: "112"},
                    {propsname: "至", propsKey: "get_end_date", propsType: "datepicker", key: "113"},
                ],
                [
                    {propsname: "客户姓名", propsKey: "user_name", propsType: "input", key: "115"},
                    {propsname: "使用时间", propsKey: "upd_start_date", propsType: "datepicker", key: "112"},
                    {propsname: "至", propsKey: "upd_end_date", propsType: "datepicker", key: "113"},
                ],
                [
                    {propsname: "兑换券编号", propsKey: "product_id", propsType: "input", key: "116"},
                    {propsname: "兑换券名称", propsKey: "share_type", propsType: "input", key: "117"},
                ],
                [
                    {propsname: "活动名称", propsKey: "activity_name", propsType: "input", key: "119"},
                    {propsname: "活动类型", propsKey: "activity_type", propsType: "select", key: "117"},
                ]
            ]
        };
        return (
            <div>
                <SearchDemo search={this.search.bind(this)} searchConfig={searchConfig}></SearchDemo>
                <Table {...config.tableConfig} scroll={{x: 2985}}></Table>
                <Modal key={Math.random()} title="兑换记录" visible={this.state.visible}
                       onCancel={this.handleCancel.bind(this)} closable={false}>

                </Modal>
            </div>
        );
    }
}

export default UserdhjResultSelect;